﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using CoolCode.Entities;
using CoolCode.Models;

namespace CoolCode.Web.Security
{
    public class LogBuilder
    {
        public static ILog Log(UserAction action, string key, string message)
        {
            string type = action.GetAttachedString();
            return new Log
            {
                Name = key,
                Type = type,
                Desc = message,
                From = RequestUtility.GetIP(),
                User = HttpContext.Current.User.Identity.Name,
                Path = RequestUtility.GetUrl(),
                Time = DateTime.Now
            };
        }

    }

    public static class ContextExtensions
    {
        public static ILog BuildLog(this IHttpHandler context, UserAction type, string key, string message)
        {
            return LogBuilder.Log(type, key, message );
        }

         
    }
}
